package com.java.config;

import javax.sql.DataSource;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import com.alibaba.druid.pool.DruidDataSource;

/**
 * <p>
 * ORM数据源配置
 * </p>
 * 
 * 
 */
@Configuration
public class DataSourceConfiguration {

    /**
     * 定义数据源 ,参数来自 application.yml 中前缀为druid
     *
     * @return
     */

    @Primary
    @Bean
    @ConfigurationProperties(prefix = "sys.druid")
    public DataSource dataSource() {
        return new DruidDataSource();
    }

    @Bean
    JdbcTemplate jdbcTemplate(){
        return new JdbcTemplate(dataSource());
    }

}
